public class LeetCode303 {

    private SegmentTree<Integer> segmentTree;
    public LeetCode303(int[] nums) {
        // 先将int数组转换为Integer数组，这样才可以使用现成的方法
        Integer[] integers = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            integers[i] = nums[i];
        }
        segmentTree = new SegmentTree<Integer>(integers,((a, b) -> a+b));
    }

    public int sumRange(int left, int right) {
        if (segmentTree ==null){
            throw new IllegalArgumentException("Segment Tree is null!");
        }

        return segmentTree.query(left, right);
    }


/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray obj = new NumArray(nums);
 * int param_1 = obj.sumRange(left,right);
 */
}
